var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //tabs: ['待抢购', '在进行', '已结束'],
    tabIndex: 1,
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      tabs: ['待' + options.title, '在进行', '已结束'],
      tabs_title: options.title
    })
    var that = this;
    if (!app.globalData.userInfo) {
      app.getUserInfo();
    }
    this.setData({
      userInfo: app.globalData.userInfo,
    })
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });

    wx.setNavigationBarTitle({
      title: options.title,
    })
    app.ihttpGet('https://www.58zltc.com/api.php/Goods/index/huodong/' + options.type, res=>{
      this.setData({
        goods_list: res.data
      })
    })
  },
  bindChange: function (e) {

    var that = this;
    that.setData({ currentTab: e.detail.current });

  },
  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
    //砍价检索
    if (that.data.tabs_title == '砍价') {
      console.log(that.data.tabs_title)
      app.ihttpGet('https://www.58zltc.com/api.php/Goods/index/huodong/kan/clickType/' + e.target.dataset.current, res => {
        that.setData({
          goods_list: res.data
        })
      })
    }
    //抢购检索
    if (that.data.tabs_title == '抢购') {
      console.log(that.data.tabs_title)
      app.ihttpGet('https://www.58zltc.com/api.php/Goods/index/huodong/qiang/clickType/' + e.target.dataset.current, res => {
        that.setData({
          goods_list: res.data
        })
      })
    }
    //拼团检索
    if (that.data.tabs_title == '拼团') {
      console.log(that.data.tabs_title)
      app.ihttpGet('https://www.58zltc.com/api.php/Goods/index/huodong/pin/clickType/' + e.target.dataset.current, res => {
        that.setData({
          goods_list: res.data
        })
      })
    }
  },
  setTab: function (e) {
    // console.log(e);
    var index = e.currentTarget.dataset.index;
    this.setData({
      tabIndex: index
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})